package com.bleeth.kettle.config;

import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollUtil;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

import java.util.List;

/**
 * [Sa-Token 权限认证] 全局配置类
 */

public class AuthInterceptor implements Interceptor {


    @Override
    public void intercept(Invocation inv) {
        // 登录验证 -- 拦截所有路由，并排除/user/doLogin 用于开放登录
        List<String> patternList = CollUtil.newArrayList("/**");
        List<String> excludeList = CollUtil.newArrayList(
                "/sys/login",
                "/doc.html",
                "/func/test",
                "/sys/access/login",
                "/swagger-resources",
                "/webjars/**",
                "/favicon.ico",
                "/v2/api-docs"
        );
        SaRouter.match(patternList, excludeList, () -> StpUtil.checkLogin());
        inv.invoke();
    }
}